/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import Beans.WatchList;
import datas.WatchListMapper;
import java.util.List;
import org.apache.ibatis.session.SqlSession;

/**

 @author jtanguay
 */
public class WatchListDao {

  //Recuperation des favoris pour un user
  public static List<WatchList> getWatchListUser(int idUser) {
    SqlSession session = MyBatisManager.getSqlSession();

    try {
      WatchListMapper mapper = session.getMapper(WatchListMapper.class);
      List<WatchList> favoriteList = mapper.getFavoriteForUser(idUser);

      return favoriteList;
    } finally {
      MyBatisManager.closeConnexion();
    }
  }

  //Inserer un favori pour un user
  public static int insertInWatchList(int idUser, int idWatchedUser, boolean isOnWhiteList) {
    SqlSession session = MyBatisManager.getSqlSession();

    try {
      WatchListMapper mapper = session.getMapper(WatchListMapper.class);
      int returnValue = mapper.insertFavorite(idUser, idWatchedUser, isOnWhiteList);

      session.commit();

      return returnValue;
    } finally {
      MyBatisManager.closeConnexion();
    }
  }

  //Delete un favori pour un user
  public static int deleteInWatchList(int idUser, int idWatchedUser) {
    SqlSession session = MyBatisManager.getSqlSession();

    try {
      WatchListMapper mapper = session.getMapper(WatchListMapper.class);
      int returnValue = mapper.deleteWatchList(idUser, idWatchedUser);

      session.commit();

      return returnValue;
    } finally {
      MyBatisManager.closeConnexion();
    }
  }
}
